﻿Public Class NewTimeSetting
    Dim DATimeSetting As New DSReservationTableAdapters.TIME_SETTINGTableAdapter

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If ValidateTextField(TxtDurationStay, "", ErrTimeSetting) = False Then Exit Sub
        If ValidateTextField(txtHoursStay, "", ErrTimeSetting) = False Then Exit Sub
        If ValidateTextField(TxtDurationPrice, "", ErrTimeSetting) = False Then Exit Sub

        If LblSaveOption.Text = "0" Then
            If MessageBox.Show("Do you want to save?", "Save", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                If DATimeSetting.InsertNewTimeSetting(TxtDurationStay.Text, txtHoursStay.Text, TxtDurationPrice.Text) = 1 Then
                    Me.DialogResult = Windows.Forms.DialogResult.OK
                Else
                    MessageBox.Show("Error save time setting.", "Save", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            End If
        Else
            If MessageBox.Show("Do you want to update?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                If DATimeSetting.UpdateTimesetting(TxtDurationStay.Text, txtHoursStay.Text, TxtDurationPrice.Text, LblSaveOption.Text) = 1 Then
                    Me.DialogResult = Windows.Forms.DialogResult.OK
                Else
                    MessageBox.Show("Error update time setting.", "Update", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            End If
        End If
    End Sub

    Private Sub txtHoursStay_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtHoursStay.KeyPress
        SetDisableKeyString(e)
    End Sub

    Private Sub TxtDurationPrice_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtDurationPrice.KeyPress
        SetDisableKeyString(e)
    End Sub
End Class